package cn.legend.travel.admin.destination.dao.persist.repository.impl;

import cn.legend.travel.admin.destination.dao.persist.mapper.DelicacyDetailMapper;
import cn.legend.travel.admin.destination.dao.persist.repository.IDelicacyDetailRepository;
import cn.legend.travel.admin.destination.pojo.entity.DelicacyDetail;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class DelicacyDetailRepositoryImpl implements IDelicacyDetailRepository {
    private final DelicacyDetailMapper mapper;

    @Override
    public int update(Long id, String content) {
        DelicacyDetail detail = new DelicacyDetail();
        detail.setContent(content);
        QueryWrapper<DelicacyDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("delicacy_id", id);
        return mapper.update(detail, wrapper);
    }

    @Override
    public int deleteByDelicacy(Long id) {
        QueryWrapper<DelicacyDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("delicacy_id", id);
        return mapper.delete(wrapper);
    }

    @Override
    public int addNew(Long id, String content) {
        DelicacyDetail detail = new DelicacyDetail();
        detail.setDelicacyId(id);
        detail.setContent(content);
        return mapper.insert(detail);
    }
}
